﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace wms.Common
{
   static class ChangeLanguage
    {
        /// <summary>
        /// 改变语言（Window）
        /// </summary>
        /// <param name="currentLang"></param>
        /// <param name="w"></param>
        public static void change(string currentLang, Window w)
        {
            System.Windows.ResourceDictionary langRd = null;


            CultureInfo currentCultureInfo = CultureInfo.CurrentCulture;
          
          
            try
            {
                langRd =
                System.Windows.Application.LoadComponent(
                new Uri(currentLang + ".xaml", UriKind.Relative)) as ResourceDictionary;


            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
            if (langRd != null)
            {
                if (w.Resources.MergedDictionaries.Count > 0)
                {
                    w.Resources.MergedDictionaries.Clear();
                }
                w.Resources.MergedDictionaries.Add(langRd);

            }

        }

        /// <summary>
        /// 改变语言（Page）
        /// </summary>
        /// <param name="currentLang"></param>
        public static void changePage(string currentLang)
        {
            System.Windows.ResourceDictionary langRd = null;

            CultureInfo currentCultureInfo = CultureInfo.CurrentCulture;
            try
            {
                langRd =
               System.Windows.Application.LoadComponent(
                new Uri(currentLang + ".xaml", UriKind.Relative)) as ResourceDictionary;
            }
            catch
            {
            }
            if (langRd != null)
            {
                Application.Current.Resources.MergedDictionaries.Clear();
                Application.Current.Resources.MergedDictionaries.Add(langRd);

            }

        }

    }
}
